package com.xgkj.diyiketang.task;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xgkj.diyiketang.data.DesireInfo;
import com.xgkj.diyiketang.http.CouponHttpRequest;
import com.xgkj.diyiketang.http.CouponHttpResponse;
import com.xgkj.diyiketang.http.engine.CouponHttpBaseTask;
import com.xgkj.diyiketang.http.engine.TaskResultCode;

/**
 * Created by windo on 17/1/3.
 */

public class YuanwangDetailTask extends CouponHttpBaseTask{
    private String desireId;
    private String  isConfirm;
    public YuanwangDetailTask(String id,String confirm) {
        super();
        desireId = id;
        isConfirm = confirm;
    }

    @Override
    protected void processResponseData(CouponHttpResponse response) {
        JSONObject resp = response.getBody();
        String data = resp.getString("data");
        DesireInfo info = JSON.parseObject(data,DesireInfo.class);
        notifyTaskCompleted(TaskResultCode.SUCCESS,info);
    }

    @Override
    protected void prepareRequest() {
        super.prepareRequest();
        if (mPhase == TASK_PHASE_INIT){
            CouponHttpRequest request = new CouponHttpRequest();
            request.setApiNo(ApiNo.YUANWANG_DETAIL);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("desireId",desireId);
            jsonObject.put("isConfirm",isConfirm);
            request.setData(jsonObject.toString());
            addRequest(request);
        }
    }
}
